package la.renzhen.rtpt.spring.boot.endpoint;

import la.renzhen.rtpt.config.ConfigurationSource;
import la.renzhen.rtpt.config.source.SpringConfigurationSource;
import la.renzhen.rtpt.spring.boot.RTPTProperties;
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Map;

/**
 * <p>
 *
 * @author <a href="mailto:zhouhaichao@2008.sina.com">haiker</a>
 * @version 10/05/2018 4:18 PM
 */
@ConfigurationProperties(prefix = "endpoints." + RTPTProperties.PREFIX)
public class RTPTEndpoint extends AbstractEndpoint<Map<String, String>> {

    SpringConfigurationSource source;
    String environment;
    String prefix;

    public RTPTEndpoint(SpringConfigurationSource source, String environment, String prefix) {
        super(RTPTProperties.PREFIX);
        this.source = source;
        this.environment = environment;
    }

    @Override
    public Map<String, String> invoke() {
        return source.loadAll(environment, prefix);
    }

    public ConfigurationSource getSource() {
        return source;
    }
}
